<!-- 招生方案列表 -->
<template>
	<zh-app style="background-color: #FFFFFF;font-family: '阿里巴巴普惠体'">
		<!-- 导航栏 -->
		<zh-navbar title="小学招生方案" color="#85a5ff" linear="right" :hideHome="true" :hideBack="true"/>
		
		<zh-sheet :padding="[0,0]" :margin="[30,20]">
			<zh-input
				:height="80" 
				v-model="data.searchText"
				placeholder="搜索标题" 
				placeholderStyle="text-align: center;" 
				 :transprent="false"
				
				showClear
			/>
		</zh-sheet>
		<!-- 筛选结果列表 -->
		<z-paging
					ref="paging"
					:fixed="false"
					height="90vh"
					@query="onQueryList"
					v-model="data.planList"
					:show-scrollbar="false"
				>
					<template v-slot:empty>
						<zh-result
							:showBtn="false"
							title="未搜索到方案信息"
							subTitle="请重新选择条件"
						></zh-result>
					</template>
					<z-paging-cell
						v-for="(item, index) in data.planList"
						:key="item.enrollmenBrochureId"
					>
					<zh-card
						:margin="[30,30]"
						color="#F0F5FF" 
						:status="item.publishTimeText" 
						:title="item.schoolName" 
						:content="item.title"
						@tap="goToDetail(item.enrollmenBrochureId)"
					></zh-card>
					</z-paging-cell>
				</z-paging>
		<zlb-footer></zlb-footer>
		
	</zh-app>
</template>
<script lang="ts" setup>
	import {reactive,watch,ref} from "vue";
	import { onLoad } from "@dcloudio/uni-app";
	// ------------------接收传入参数(组件)-------------------

	// ------------------钩子函数----------------------------
	// 初始化
	onLoad((options: any) => {
		queryArea();
		initYear();
	})

	// ------------------变量区------------------------------
	const paging=ref();
	// 主数据
	const data = reactive({
		schoolCategory:'2',
		// 搜索关键字
		searchText: '',
		
		// 当前选择的年度
		selectYear: {
			name: '全部',
			value: 'all'
		},
		// 招生年度
		yearArr: [
			{
				name: '全部',
				value: 'all'
			}
		],
		// 当前选择的统筹区
		selectArea: {
			name: '全部',
			value: 'all'
		},
		// 统筹区
		areaArr: [
			{
				name: '全部',
				value: 'all'
			}
		],
		canSearch:false,
		planList:[] as any
	})

	// ------------------方法区------------------------------
	
	//名称搜索输入
	watch(
	  () => data.searchText,
	  () => {
	    data.canSearch=true
		onSearch()
	  },
	  { deep: true }
	);
	//关闭筛选器的时候触发搜索
	function onSearch() {
		if(data.canSearch){
			uni.$tm.u.debounce(() => paging.value?.reload(), 500)
		}
	}
	//
	const onSchoolCategoryChange=()=>{
		paging.value?.reload()
	}
	
	const onQueryList = (pageNo :number, pageSize:number) => {
		//获取通知招生方案列表
		let params :any={}
		params.searchText=data.searchText
		if(data.selectArea.value!=='all'){
			params.areaCode=data.selectArea.value
		}
		if(data.schoolCategory!=='all'){
			params.schoolCategory=data.schoolCategory
		}
		if(data.selectYear.value!=='all'){
			params.year=data.selectYear.value
		}
		
		params.pageNum = pageNo
		params.pageSize = pageSize
		$api.common.send.post("Eduenrollmen0007",params).then((res:any)=>{
			paging.value?.complete(res.result.list || [])
		}).catch(() => {
			paging.value?.complete(false)
		})
	}
	// 跳转方案详情页
	const goToDetail = (enrollmenBrochureId: any) => {
		let params ={enrollmenBrochureId:enrollmenBrochureId}
		$router.push('/pages/edu/enrollPlan/enrollmenDetail',params);
	}
	//生成 年度选择
	const initYear=()=>{
		//当前年度
		let cur=new Date().getFullYear();
		let min=2020
		let yearArr=[]
		let j=1;
		for(let i=cur;i>=min;i--){
			if(j>10){
				break;
			}
			let item={name:i+"年",value:i+''}
			yearArr.push(item)
			j=j+1;
		}
		data.yearArr=yearArr
	}
	
	//查询统筹区
	const queryArea=()=>{
		let params :any={}
		params.dictField = 'AREAEDU'
		$api.common.getDict.post(params).then((res:any)=>{
			
			if(res.result&&res.result.length>0){
				let areaArr :any=[]
				res.result.forEach((el:any) => {
					if(!el.parentKey||'#'===el.parentKey){
						let item={name:el.dictValue,value:'all'}
						data.selectArea=item
						areaArr.push(item)
					}else{
						let item={name:el.dictValue,value:el.dictKey}
						areaArr.push(item)
					}
				})
				data.areaArr=areaArr;
			}
			
		})
	}
</script>
<style scoped></style>
